package com.ruoyi.common.utils.check;


import java.util.Collection;
import java.util.Map;

/**
 * 判空类
 * @author ZhangKeChen
 * @date 2022/8/30
 */

public class CheckEmptyUtil {
    public static final String ContiguousUSStateCodes = "AL|AZ|AR|CA|CO|CT|DE|DC|FL|GA|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY";


    /**
     * 两个对象比较方法
     * @param obj
     * @param obj2
     * @return
     */
    public static boolean areEqual(Object obj, Object obj2) {
        if (obj == null) {
            return obj2 == null;
        } else {
            return obj.equals(obj2);
        }
    }

    /**
     * 忽略大小写比较方法
     * @param obj
     * @param obj2
     * @return
     */
    public static boolean areEqualIgnoreCase(String obj, String obj2) {
        if (obj == null) {
            return obj2 == null;
        } else {
            return obj.equalsIgnoreCase(obj2);
        }
    }

    /**
     * 判断对象是否为空
     * @param value
     * @return
     */
    public static boolean isEmpty(Object value) {
        if (value == null) {
            return true;
        } else if (value instanceof String) {
            return ((String) value).length() == 0;
        } else if (value instanceof Collection) {
            return ((Collection<?>) value).isEmpty();
        } else if (value instanceof Map) {
            return ((Map<?, ?>) value).size() == 0;
        } else if (value instanceof String[]) {
            return ((String[]) ((String[]) value)).length == 0;
        } else {
            return false;
        }
    }

    public static boolean isEmpty(String s) {
        return s == null || s.length() == 0;
    }

    public static boolean isEmpty(Collection c) {
        return c == null || c.isEmpty();
    }

    public static boolean isNotEmpty(String s) {
        return s != null && s.length() > 0;
    }

    public static boolean isNotEmpty(Collection c) {
        return c != null && !c.isEmpty();
    }

    public static boolean isString(Object obj) {
        return obj instanceof String;
    }
}
